/**
 * JS модель Пользователя
 * Содержит все необходимые атрибуты
 * @param {type} params
 * @returns {undefined}
 */
function User(params){
	params = params || {};
	var self = this;
	
	self.id = ko.observable(parseInt(params.id));
	self.first_name = ko.observable(params.first_name);
	self.last_name = ko.observable(params.last_name);
	self.role = ko.observable(params.role);
	self.name = ko.computed(function(){
		return self.first_name() + ' ' + self.last_name();
	});
	
	self.isSame = function(compareModel){
		return compareModel !== null && compareModel.id() === self.id();
	};
	
	self.openIssues = ko.observableArray([]);
	self.openIssues.id_status = IssueStatus.STATUS_OPEN;
	self.openIssues.id_user = self.id();
	
	self.resolvedIssues = ko.observableArray([]);
	self.resolvedIssues.id_status = IssueStatus.STATUS_RESOLVED;
	self.resolvedIssues.id_user = self.id();
	
	self.verifiedIssues = ko.observableArray([]);
	self.verifiedIssues.id_status = IssueStatus.STATUS_VERIFIED;
	self.verifiedIssues.id_user = self.id();
	
	all.issues.subscribe(function(issues){
		var userOpenIssues = [];
		var userResolvedIssues = [];
		var userVerifiedIssues = [];
		ko.utils.arrayForEach(issues, function(issue){
			if(self.isSame(issue.assignee())){
				if(issue.isOpen()){
					userOpenIssues.push(issue);
				}
				if(issue.isResolved()){
					userResolvedIssues.push(issue);
				}
				if(issue.isVerified()){
					userVerifiedIssues.push(issue);
				}
			}
		});
		userOpenIssues.sort(compareIssues);
		userResolvedIssues.sort(compareIssues);
		userVerifiedIssues.sort(compareIssues);
		
		self.openIssues(userOpenIssues);
		self.resolvedIssues(userResolvedIssues);
		self.verifiedIssues(userVerifiedIssues);
	});
}